using System;
using System.Collections.Generic;
using System.Text;
using QLPMT_DTO;
using QLPMT_DAO;
namespace QLPMT_BUS
{
  public  class LoaiBenhBUS
    {
      public List<LoaiBenh> GetAll()
      {
          return new BenhDAO().GetAll();
      }
      //Lay Ma loai benh cuoi cung
      public string GetMaLoaiBenh()
      {
          List<LoaiBenh> list = new List<LoaiBenh>();
          list = new BenhDAO().GetAll();
          LoaiBenh temp=new LoaiBenh();
          foreach (LoaiBenh X in list)
          {
              temp.Maloaibenh= X.Maloaibenh;
          }
          string ma = "";
          if (temp.Maloaibenh != null)
          {
              char[] chuoi = temp.Maloaibenh.ToCharArray(2, temp.Maloaibenh.Length - 2);
              string chuoima = "";
              foreach (char charX in chuoi)
              {
                  chuoima = chuoima + charX;
              }
              int soloaibenh = int.Parse(chuoima) + 1;
              ma = "LB" + soloaibenh.ToString();
          }
          else
              ma = "LB1";
          return ma;
      }
      // Them loai benh moi vao danh sach
      public Boolean InsertLoaiBenh(string tenloaibenh)
      {
          try
          {
          
              string maloaibenh = GetMaLoaiBenh();
              LoaiBenh dto = new LoaiBenh(maloaibenh, tenloaibenh);
              BenhDAO dao = new BenhDAO();
              dao.InsertLoaiBenh(dto);

          
          }
          catch
          {
              return false;
          }
          return true;
      }
      public Boolean sualoaibenh(string tenloaibenh, string ma)
      {
          try
          {
              LoaiBenh l = new LoaiBenh(ma, tenloaibenh);
              BenhDAO dao = new BenhDAO();
              dao.sualoaibenh(l);


          }
          catch
          {
              return false;

          }
          return true;
      }
    }
}
